============================================================================= - DRAG & DROP - ============================================================================= - This code illustrates one method of implementing drag&drop within a TList control (can also be used between two TList controls). A future version of TList may support internal Drag&Drop without VB code, but we will need to look for feedback from our users first to insure that we do this in an appropriate manner. '---------------------------------------------------------------------------- To use these DragDrop procedures with TList you should do as follows: 1. Set DragMode for TList to 0 - Manual. 2. Set DragIcon to the icon you would like to use. I prefer icons from \DRAGDROP standard VB directory. 3. Set DragHighlight to True - otherwise items won't be highlighted when the user drags over them. 4. Set TList.Tag to the string "TREE". There is no difference what string is in the Tag, but code in the DragDrop event assumes that this line is ID of TList control. 5. Add code which is below: 5.1 Add global variables hTreeBuffer& - here we store a Tree Buffer for items that we drag. XCheck, YCheck - In these variables we save X and Y coordinates of mouse cursor position when the user presses the left mouse button(MouseDown event). Note, that we cannot start Dragging on the first MouseMove event. If we did so, the user would be starting a Drag each time he hit the left mouse button. Thus, to initiate Dragging, the user must press the left mouse button and move the mouse a little, keeping the left mouse button pressed. In this code we start Dragging only if user moves the mouse with left button depressed for a distance of at least 100 twips. 5.2 Add code for MouseDown, MouseMove, DragDrop and Form_Unload events. 5.3 There is also some code for expanding and collapsing items on double-click. 6. How it works: 6.1. User presses left mouse button and moves the mouse for the distance more than 100 twips. We process MouseDown event - set XCheck & YCheck to 0 We process MouseMove event until difference in X or Y parameters is more than 100 twips. 6.2. In MouseMove event we do: 6.2.1 set XCheck & YCheck to 0. 6.2.2 If (TList has an item, specified by ListIndex property) Then 6.2.2.1 free Tree Buffer(there can be items from previous drag/drop operations). 6.2.2.2 copy item whose index is specified by ListIndex property to the Tree Buffer by CopyItem property. (If you need to copy all selected items use CopySelected property, if you want to copy only subordinate items use CopyItemSub property) 6.2.2.3 remove item that we copy by RemoveItem method. Note, there are extra .Redraw calls - they cause updating of TList after removing of an item, otherwise highlighted item isn't drawn correctly after it. EndIf 6.2. Mouse cursor changes as the user moves it over items of TList Items that are dragged over are highlighted automatically. 6.3. User drops on one of the items, triggering the DragDrop event. Within the DragDrop event we check the Source.Tag property and if we find the string "TREE", we assume that Source is a TList control. Then we do as follows: 6.3.1 Get target item index from tltSample.DropTarget property 6.3.2 Set Redraw to False(Prevent control from immediate repainting) 6.3.3 Expand target item(It may or may not have items but flag is set anyway). 6.3.4 Add items from Tree Buffer using the Add property. This property adds items which are stored in the Tree Buffer as subordinate items to the item specified by index. You can use Insert property to add items before item specified by index on the same level. 6.3.5 Turn repainting on by setting Redraw to True. 6.3.6 Release the TreeBuffer memory